package com.xaicode.auth.service.impl;

import cn.hutool.core.util.StrUtil;
import com.xaicode.auth.base.BaseMpServiceImpl;
import com.xaicode.auth.entity.SysOperLog;
import com.xaicode.auth.mapper.SysOperLogMapper;
import com.xaicode.auth.security.domain.params.SysOperLogQueryParam;
import com.xaicode.auth.service.ISysOperLogService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class SysOperLogServiceImpl extends BaseMpServiceImpl<SysOperLogMapper, SysOperLog> implements ISysOperLogService {

    @Override
    public PageInfo<SysOperLog> queryPage(SysOperLogQueryParam param) {
        startPage(param);
        List<SysOperLog> list = queryList(param);
        return PageInfo.of(list);
    }

    @Override
    public List<SysOperLog> queryList(SysOperLogQueryParam param) {
        LambdaQueryWrapper<SysOperLog> lqw = Wrappers.lambdaQuery();
        lqw.eq(Objects.nonNull(param.getStatus()), SysOperLog::getStatus, param.getStatus());
        lqw.eq(Objects.nonNull(param.getBusinessType()), SysOperLog::getBusinessType, param.getBusinessType());
        lqw.like(StrUtil.isNotBlank(param.getTitle()), SysOperLog::getTitle, param.getTitle());
        lqw.like(StrUtil.isNotBlank(param.getOperName()), SysOperLog::getOperName, param.getOperName());
        lqw.like(StrUtil.isNotBlank(param.getReqUrl()), SysOperLog::getReqUrl, param.getReqUrl());
        List<SysOperLog> list = list(lqw);
        return list;
    }

}
